<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>用户需求管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
	var yes = ${fns:getDictValue('是','yes_no','')}; // 字典yes_no的“是”
		$(document).ready(function() {
			// 根据是否发布给公众作处理
			$('input[name=ispublic]').change(function(){
				var val = $('input[name=ispublic]:checked').val();
				if(val == yes) {
					$('.release').hide();
				} else {
					$('.release').show();
				}
			});
			$('input[name=ispublic]').change();
			
			//$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					// 如果是发布给公众，则清除发布对象
					if($('input[name=ispublic]:checked').val()==yes){
						$('#releaseobject').val('');
					}
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			// 正整数
			$.validator.addMethod("positive", function(value, element) {
				if(value<=0){
					return false;
				}else {
					return true;
				}
			}, "不能为0");
			// 出发城市不能与到达城市相同
			$.validator.addMethod("sameCity", function(value, element) {
				var departcity = $('#departcityId').val();
				var destcity = $('#destcityId').val();
				if(departcity == destcity){
					return false;
				} 
				return true;
			}, "出发城市不能与到达城市相同");
			$.validator.addMethod("mobile", function(value, element) {
				var length = value.length;
				var mobile = /^1[3|4|5|7|8]\d{9}$/;
				return this.optional(element) || (length == 11 && mobile.test(value));
			}, "手机号格式不对");
			
			$("#releaseobjectBtn").click(function(){
				top.$.jBox.open("iframe:${ctx}/rentproduct/tRentproduct/enterpriseList?demandid=${tDemands.demandid}", "旅行商", 500, $(top.document).height()-180, {
		            buttons:{"确定":"ok", "关闭":true}, submit:function(v, h, f){
	                	var val = h.find("iframe")[0].contentWindow.selectedVals();
	                	var num = 0;
	                	if(val!=''){
	                		num = val.split(',').length;
	                	}
	                	$('#releaseobjectBtn span').text(num);
	                	$('#releaseobject').val(val);
		            }, loaded:function(h){
		                $(".jbox-content", top.document).css("overflow-y","hidden");
		            }
		        });
			});
		});
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/rentproduct/tDemands/">需求列表</a></li>
		<li class="active"><a href="${ctx}/rentproduct/tDemands/form?demandid=${tDemands.demandid}">需求<shiro:hasPermission name="rentproduct:tDemands:edit">${not empty tDemands.demandid?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="rentproduct:tDemands:edit">查看</shiro:lacksPermission></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="tDemands" action="${ctx}/rentproduct/tDemands/save" method="post" class="form-horizontal">
		<form:hidden path="demandid"/>
		<sys:message content="${message}"/>
		<div class="control-group">
			<label class="control-label">车型描述：</label>
			<div class="controls">
				<form:textarea path="modeldesc" htmlEscape="false" rows="4" maxlength="100" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font></span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">座位数：</label>
			<div class="controls">
				<form:input path="seats" htmlEscape="false" class="input-mini required digits positive"/>
				<span class="help-inline"><font color="red">*</font>座</span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">租赁开始日期：</label>
			<div class="controls">
				<input id="fromdate" name="fromdate" type="text" readonly="readonly" maxlength="20" class="input-small Wdate required" style="width:140px;"
					value="<fmt:formatDate value="${tDemands.fromdate}" pattern="yyyy-MM-dd HH:mm"/>"
					onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm',isShowClear:false});"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">租赁天数：</label>
			<div class="controls">
				<form:input path="rentdays" htmlEscape="false" class="input-mini required digits positive"/>
				<span class="help-inline"><font color="red">*</font>天</span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">租赁数量：</label>
			<div class="controls">
				<form:input path="vehiclenum" htmlEscape="false" class="input-mini required digits positive"/>
				<span class="help-inline"><font color="red">*</font>辆</span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">出发/到达城市：</label>
			<div class="controls">
				<sys:treeselect id="departcity" name="departcity.code" value="${tDemands.departcity.code}"
					labelName="departcity.name" labelValue="${tDemands.departcity.name}" title="出发城市"
					url="/sys/area/treeData" cssClass="input-mini sameCity required" allowClear="true" hideBtn="true" dataMsgRequired="出发城市不能为空" valueAttr="code"
					notAllowSelectParent="true"/>
				<span class="help-inline"><font color="red">*</font>－</span>
				<sys:treeselect id="destcity" name="destcity.code" value="${tDemands.destcity.code}"
					labelName="destcity.name" labelValue="${tDemands.destcity.name}" title="出发城市"
					url="/sys/area/treeData" cssClass="input-mini" allowClear="true" hideBtn="true" valueAttr="code"
					notAllowSelectParent="true"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">联系人：</label>
			<div class="controls">
				<form:input path="contactor" htmlEscape="false" maxlength="50" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font></span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">联系电话：</label>
			<div class="controls">
				<form:input path="contactphone" htmlEscape="false" maxlength="20" class="input-xlarge required mobile"/>
				<span class="help-inline"><font color="red">*</font></span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">备注：</label>
			<div class="controls">
				<form:textarea path="remarks" htmlEscape="false" rows="4" maxlength="200" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font></span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">期望价格：</label>
			<div class="controls">
				<form:input path="hopeprice" htmlEscape="false" class="input-mini required money positive"/>
				<span class="help-inline"><font color="red">*</font>元</span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">是否发布给所有公司：</label>
			<div class="controls">
				<c:forEach items="${fns:getDictList('yes_no')}" var="yes_no">
					<label class="radio"><input type="radio" name="ispublic" value="${yes_no.value}" ${yes_no.value == tDemands.ispublic?'checked':''}/>${yes_no.label}</label>
				</c:forEach>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group release">
			<label class="control-label">发布对象：</label>
			<div class="controls">
				<button type="button" class="btn btn-link" id="releaseobjectBtn">共<span>${objCount }</span>个旅行商</button>
				<input id="releaseobject" name="releaseobject" type="hidden" />
			</div>
		</div>
		<div class="form-actions">
			<shiro:hasPermission name="rentproduct:tDemands:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>